<!--
 * @Author: 刘翔
 * @Date: 2025-08-06 10:50:37
 * @LastEditTime: 2025-09-01 16:34:49
 * @LastEditors: your name
 * @Description:组合页面6(基础病组科室分布)
 * @FilePath: \建达文件\ts-demo\ts-demo\src\pptHome\pageList\pageType6.vue
-->
<template>
  <div class="page-type-6">
    <div class="page-type-6-top">
      <DataTable ref="table1" v-bind="getTableProps1()" />
    </div>
    <div class="page-type-6-bottom">
      <CardBox>
        <template #right>
          <span class="card-box-right-item-1" v-html="desc"></span>
        </template>
      </CardBox>
    </div>
  </div>
</template>

<script>
import DataTable from '../components/DataTable.vue';
import CardBox from '../components/cardBox.vue';
export default {
  name: 'pageType6',
  components: {
    DataTable,
    CardBox,
  },
  props: {
    tableData1: {
      type: Object,
      default: () => {},
    },
    desc: {
      type: String,
      default: '',
    },
  },
  methods: {
    getTableProps1() {
      return {
        tableData: this.tableData1.data,
        columns: this.tableData1.columns,
        tableParams: {
          headerHeight: 60,
        },
        pptOptions: {
          x: 0.3, // X轴位置
          y: 0.8, // Y轴位置
          h: 3.6, // 高度
          title: {
            // 标题配置
            x: 0.5,
            y: 0.5,
            fontSize: 24,
            color: '363636',
            bold: true,
          },
          table: {
            // 表格配置
            colW: this.tableData1.columns.map(item => this.pptWidthPercentFn(item.widthPercent)),
            // 表格内容配置
            content: {
              fontSize: 8,
              color: '000000',
              bold: true,
            },
            // 表格标题配置
            title: {
              fontSize: 8,
              color: 'ffffff',
            },
            // 表格边框样式
            borderStyle: {
              color: '000000',
            },
            // 表格垂直对齐方式(middle, top, bottom)
            valign: 'middle',
            // 表格水平对齐方式(left, center, right)
            align: 'center',
            // 自动分页
            autoPage: false,
            // 自动分页标题是否显示
            autoPageRepeatHeader: false,
            // 自动分页标题行数
            autoPageHeaderRows: 1,
          },
        },
      };
    },
    // 计算ppt宽度百分比(9.8是ppt表格目前总宽度)
    pptWidthPercentFn(pptWidthPercent) {
      return (pptWidthPercent / 100) * 9.8;
    },
    // 解析带颜色的文本
    parseColoredText(text) {
      return text
        .split(/(<span[^>]*>.*?<\/span>)/)
        .filter(part => part) // 移除空字符串
        .map(part => {
          const match = part.match(/<span[^>]*color:(#[0-9a-f]+)[^>]*>(.*?)<\/span>/i);
          return match ? { text: match[2], color: match[1] } : { text: part, color: '#000000' };
        });
    },
    exportToPPT(pptx, slide) {
      this.$refs.table1.exportToPPT(pptx, slide);
      let textList = [];
      this.parseColoredText(this.desc).forEach(item => {
        textList.push({
          text: item.text,
          options: {
            fontSize: 12,
            color: item.color,
          },
        });
      });
      //卡片
      slide.addText(textList, {
        shape: pptx.shapes.ROUNDED_RECTANGLE,
        x: 0.5,
        y: 4.7,
        w: 9,
        h: 0.8,
        rectRadius: 0.2,
        //边框
        line: { color: '151515', width: 0.5 },
        fill: { color: 'fff2ca' },
      });
    },
  },
};
</script>

<style lang="less" scoped>
.page-type-6 {
  width: 100%;
  height: 100%;
  .page-type-6-top {
    width: 100%;
    height: 90%;
  }
  .page-type-6-bottom {
    width: 100%;
    height: 10%;
    font-size: 2rem;
  }
  .card-box-container {
    margin: 10px 0;
    justify-content: left;
  }
}
</style>
